package com.wintop.youyuan.services.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wintop.youyuan.dao.UserInformationDao;
import com.wintop.youyuan.model.BaseData;
import com.wintop.youyuan.model.DetailData;
import com.wintop.youyuan.model.PersonalsCondition;
import com.wintop.youyuan.model.Photo;
import com.wintop.youyuan.services.UserInformationServices;

@Service("userInformationServices")
public class UserInformationServicesImpl implements UserInformationServices {
	private UserInformationDao userInformationDao;

	@Resource(name = "userInformationDao")
	public void setUserInformationDao(UserInformationDao userInformationDao) {
		this.userInformationDao = userInformationDao;
	}

	@Override
	public BaseData getBaseData(String userid) {
		return userInformationDao.getBaseData(userid);
	}

	@Override
	public DetailData getDetailData(String userid) {
		return userInformationDao.getDetailData(userid);
	}

	@Override
	public PersonalsCondition getPersonalsCondition(String userid) {
		return userInformationDao.getPersonalsCondition(userid);
	}

	@Override
	public List<Photo> getPhotos(String userid) {
		return userInformationDao.getPhotos(userid);
	}

	@Override
	public boolean addPhoto(Photo photo) {
		return userInformationDao.addPhoto(photo);
	}

	@Override
	public boolean deletePhoto(int id) {
		return userInformationDao.deletePhoto(id);
	}

	@Override
	public boolean updateBaseData(BaseData baseData) {
		int dd = userInformationDao.getBaseDataId(baseData.getUserid());
		String icon = userInformationDao.getIcon(baseData.getUserid());
		baseData.setIcon(icon);
		baseData.setId(dd);
		return userInformationDao.updateData(baseData);
	}

	@Override
	public boolean updateDetailData(DetailData detailData) {
		int dd = userInformationDao.getDetailDataId(detailData.getUserid());
		detailData.setId(dd);
		userInformationDao.updateData(detailData);
		return true;
	}

	@Override
	public boolean updateSoliloquy(String userid, String soliloquy) {
		DetailData detailData = userInformationDao.getDetailData(userid);
		detailData.setSoliloquy(soliloquy);
		return userInformationDao.updateData(detailData);
	}

	@Override
	public boolean updatePersonalsCondition(
			PersonalsCondition personalsCondition) {
		int dd = userInformationDao.getPersonalsConditionId(personalsCondition
				.getUserid());
		personalsCondition.setId(dd);
		return userInformationDao.updateData(personalsCondition);
	}

	@Override
	public int getLoveNum(int sex, String province, String city, int minAge,
			int maxAge) {
		return userInformationDao.getLoveNum(sex, province, city, minAge,
				maxAge);
	}

	@Override
	public List<BaseData> getLoveUsers(int sex, String province, String city,
			int minAge, int maxAge, int pageNum, int pageSize) {
		return userInformationDao.getLoveBaseDatas(sex, province, city, minAge,
				maxAge, pageNum, pageSize);
	}

	@Override
	public boolean updateIcon(String userid, String icon) {
		BaseData baseData = userInformationDao.getBaseData(userid);
		baseData.setIcon(icon);
		return userInformationDao.updateData(baseData);
	}

	@Override
	public String getIcon(String userid) {
		return userInformationDao.getIcon(userid);
	}

}
